package subraSoft.centaurus.gui.components;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.Timer;
import javax.swing.border.BevelBorder;

/**
 * Ventana Splash con el logotipo de la aplicacion.
 * 
 * @author caeycae
 *
 */
@SuppressWarnings("serial")
public class CenSplashScreen extends JWindow implements Runnable, ActionListener
{
    private int timeout;

    /**
     * Constructor.
     * 
     * @param image logotipo
     * @param timeout tiempo de permanencia en la pantalla
     */
    public CenSplashScreen(ImageIcon image, int timeout)
    {
        this.timeout = timeout;
        int w = image.getIconWidth();
        int h = image.getIconHeight();
        
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (screen.width - w) / 2;
        int y = (screen.height - h) / 2;
        setBounds(x, y, w, h);
 
        getContentPane().setLayout(new BorderLayout());
        JLabel picture = new JLabel(image);
        getContentPane().add("Center", picture);
        picture.setBorder(new BevelBorder(BevelBorder.RAISED));
    }
 
    /**
     * Muestra la ventana en la pantalla.
     */
    public void run()
    {
    	setAlwaysOnTop(true);
        setVisible(true);
        Timer timer = new Timer(0, this);
        timer.setRepeats(false);
        timer.setInitialDelay(timeout);
        timer.start();
    }
 
    /**
     * Accion a realizar cuando finaliza el timer.
     * 
     * @param event evento de finalizacion del timer.
     */
    public void actionPerformed(ActionEvent event)
    {
      setVisible(false);
      dispose();

    }
}
